home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: MegaDisc
/
MegaDisc 36 (1993-11)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip
/
MegaDisc 36 (1993-11)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf
/
ARexx
/
Chars
/
CharGrid
next >
Wrap
Text File
|
1993-09-15
|
8KB
|
235 lines
/* Character Designer */
/* by John Collett */
/* Make required libraries active */
lib.1 = 'rexxsupport.library' ; lib.2 = 'rexxarplib.library'
do i = 1 to 2
if ~show('l',lib.i) then check = addlib(lib.i,0,-30,0)
end
/* Create required ports and open window */
address AREXX '"call CreateHost(HO, PORT)"'
if ~show('Ports','HO') then address command 'WaitForPort HO'
flags = 'WINDOWCLOSE+WINDOWDRAG'
idcmp = 'CLOSEWINDOW+MOUSEBUTTONS+GADGETUP'
call OpenWindow(HO,160,12,300,100,idcmp,flags,'Character Designer')
call openport(PORT) ; call ActivateWindow(HO)
call ModifyHost(HO,MOUSEBUTTONS,'%l %b %x %y')
/* S e t t i n g s */
fileopen = 0 ; left = 50 ; top = 18 ; scale = 8
right = left + 8 * scale ; bottom = top + 8 * scale ; call Box()
g.1 = 'Show ' ; g.2 = 'Save ' ; g.3 = 'Clear' ; g.4 = 'Load '
g.5 = 'Help ' ; g.6 = 'Quit '
do i = 1 to 6
call AddGadget(HO,160,14*i,i,' ' || g.i || ' ','%l %b %d')
end
call pat(224,22,'-->')
/* L o o p */
do forever
call waitpkt(PORT) ; p = getpkt(PORT)
if p ~== NULL() then
do
i = getarg(p) ; t = reply(p, 0)
parse var i class state rest
select
when i = 'CLOSEWINDOW' then signal 'finish'
when class = 'MOUSEBUTTONS' then do
parse var i class state x y .
if x > left & x < right & y > top & y < bottom then do
if state = 'SELECTDOWN' then
do ; x1 = x ; y1 = y ; end
else if state = 'SELECTUP' then
do ; x2 = x ; y2 = y ; call Cell(x1,y1,x2,y2) ; end
end
end
when class = 'GADGETUP' then do
parse var i class gad .
select
when gad = 1 then call ShowChar()
when gad = 2 then call SaveChar()
when gad = 3 then call ClearGrid()
when gad = 4 then call LoadChar()
when gad = 5 then call GetHelp()
when gad = 6 then signal 'finish'
otherwise
end /* of select gad */
end /* of class = GADGETUP */
otherwise
end /* of select */
end /* of 'p ~== NULL()' */
end /* of 'do forever' */
finish:
if fileopen then cl = close(cf)
call CloseWindow(HO)
exit
/* C e l l D i s p l a y */
Cell:
cx1 = (arg(1) - left)%scale + 1 ; cy1 = (arg(2) - top)%(scale) +1
cx2 = (arg(3) - left)%scale + 1 ; cy2 = (arg(4) - top)%(scale) +1
both = (cx1 = cx2 & cy1 = cy2) ; neither = (cx1 ~= cx2 & cy1 ~= cy2)
select
/* A single cell */
when both | neither then call DoCell(cx2,cy2)
/* A row */
when cx1 ~= cx2 then do
xmin = min(cx1,cx2) ; xmax = max(cx1,cx2)
do cell = xmin to xmax ; call DoCell(cell,cy2); end
end
/* A column */
when cy1 ~= cy2 then do
ymin = min(cy1,cy2) ; ymax = max(cy1,cy2)
do cell = ymin to ymax ; call DoCell(cx2,cell); end
end
otherwise
end
return
DoCell:
cx = arg(1) ; cy = arg(2)
if cx < 1 | cx > 8 | cy < 1 | cy > 8 then return
if c.cx.cy = 0 then co = 1 ; else co = 2
minx = left + scale * (cx-1) + 1 ; maxx = minx + scale - 2
miny = top + scale * (cy-1) + 1 ; maxy = miny + scale - 2
call AreaFill(co,minx,miny,maxx,maxy) ; call APen(1)
c.cx.cy = ~(c.cx.cy) ; call Update(cy)
return
/* Various functions */
Update:
packed = 0
do col = 1 to 8
if c.col.cy then packed = packed + 2**(8-col)
end
pstr = copies(' ',3 - length(packed)) || packed
call pat(120,19+cy*8,pstr)
return
/* */
pat:
if arg() = 4 then call APen(arg(4))
call Move(HO,arg(1),arg(2)) ; call Text(HO,arg(3))
return
/* */
APen: call SetAPen(HO,arg(1)) ; return
/* */
Frame:
parse arg lf,up,rt,bot .
call Move(HO,lf,up) ; call Draw(HO,rt,up)
call Move(HO,lf,bot) ; call Draw(HO,rt,bot)
do u = 0 to 1 ; call Move(HO,rt-u,up+u) ; call Draw(HO,rt-u,bot) ; end
do u = 0 to 1 ; call Move(HO,lf+u,bot-u) ; call Draw(HO,lf+u,up) ; end
return
/* */
Box:
call AreaFill(2,left,top,right,bottom) ; call APen(3)
/* Show cells */
do i = 1 to 7
x = left + scale*i ; call Move(HO,x,top) ; call Draw(HO,x,bottom)
end
do i = 1 to 7
y = top + scale * i ; call Move(HO,left,y) ; call Draw(HO,right,y)
end
call APen(1) ; call Frame(left-1,top,right+1,bottom)
/* Binary list - all zeros at start */
do r = 1 to 8 ; do col = 1 to 8 ; c.col.r = 0 ; end ; end
return
/* */
ShowChar:
call AreaFill(0,252,14,252 + 8,14 + 8) ; call APen(1)
do row = 1 to 8
do col = 1 to 8
if c.col.row then do
call Move(HO,252 + col,14 + row)
call Draw(HO,252 + col,14 + row) ; end
end
end
return
/* */
ClearGrid:
call Box() ; call AreaFill(0,116,20,144,84) ; call APen(1)
return
/* */
AreaFill:
call APen(arg(1)) ; call RectFill(HO,arg(2),arg(3),arg(4),arg(5))
return
/* S a v e o r L o a d */
SaveChar:
if ~fileopen then call CharFile()
label = Request(190,112,'Character label','',,'Cancel')
if fileopen then do
if label ~= '' then do
s = seek(cf,0,'e') ; w = writeln(cf,label || BuildStr()) ; end
end
return
/* Data string */
BuildStr:
str = ''
do cy = 1 to 8 ; call Update(cy) ; str = str || ',' || packed ; end
return str
LoadChar:
if ~fileopen then call CharFile()
label = Request(190,112,'Character label','',,'Cancel')
if label = '' then return
p = seek(cf,0,'b') ; found = 0
do until found | eof(cf)
t = readln(cf) ; parse var t lab ',' parms .
found = (lab = label)
end
if ~found then do
res = request(50,50,label 'not found',,'Okay') ; return ; end
/* Read in 8 packed line values */
parse var parms a.1 ',' a.2 ',' a.3 ',' a.4 ',' a.5 ',',
a.6 ',' a.7 ',' a.8 .
do j = 1 to 8
if a.j = 0 then iterate
row = y + j
/* Convert to a line of eight 0s or 1s */
octet = c2b(d2c(a.j))
do bit = 1 to 8
/* Shade in those cells which are a 1 */
if substr(octet,bit,1) then call DoCell(bit,j)
end
end
return
CharFile:
if ~fileopen then do
charfil = GetFile(160,100,,'chars','Character defs file')
if charfil ~= '' then do
if exists(charfil) then op = open(cf,charfil,'a')
else op = open(cf,charfil,'w')
fileopen = 1
end
end
return
/* H e l p */
GetHelp:
t = ' Click or click/drag/release in the grid to change\',
'cells. Use vertical or horizontal drags only.\\',
'GADGETS : \',
"'Show' See your design at actual character size.\",
"'Save' Store current character design in data file.\",
' It just appends any new entry to the file.\',
"'Clear' Clean out the grid.\",
"'Load' Edit a previously stored character. Uses\",
" the same file as 'Save'.\",
"'Help' This list."
mess = Request(50,96,t,,'Okay')
return
/* E n d */